/**
 * Created by Administrator on 2016/8/22.
 */
NodeList.prototype.forEach = Array.prototype.forEach;
var ggaz_report = [];
var fscl_report = [];
var dgaz_report = [];
var zjaz_report = [];
var nbqaz_report = [];
var pdxaz_report = [];

var path_report = 'http://pm.ht-home.cn/api/others/getProgressReportForShare.json?projectId='+window.currentProjectId;
var xhr_report = null;
if (window.XMLHttpRequest) {
    // 非IE内核
    xhr_report = new XMLHttpRequest();
}
xhr_report.open('get', path_report, true);
xhr_report.send(null);
xhr_report.onreadystatechange = function() {
    if (xhr_report.readyState === 4) {
        if (xhr_report.status === 200) {
            var jsonData_report = JSON.parse(xhr_report.responseText);
            BindData_report(jsonData_report);
        }
    }
};

function BindData_report(jsonData){
    var cusData = jsonData.data.customerMsg;
    document.getElementById("name_report").innerHTML=typeof (cusData.customerName) === 'undefined' ? '' :cusData.customerName;
    document.getElementById("man_report").innerHTML=typeof (cusData.contacts) === 'undefined' ? '' :cusData.contacts;
    document.getElementById("area_report").innerHTML= typeof (cusData.regionCode) === 'undefined' ? '' :cusData.regionCode;
    document.getElementById("address_report").innerHTML= typeof (cusData.address) === 'undefined' ? '' :cusData.address;
    //-----打钩/打叉----------------
    for(var i = 0; i<jsonData.data.progressList.length;i++){
        var k = jsonData.data.progressList[i].cpltResult;
        if(k == 'N'){
            document.getElementById(''+(i+1)+'_report').innerHTML='×';
        }else if(k == 'Y'){
            document.getElementById(''+(i+1)+'_report').innerHTML='√';
        }else{
            document.getElementById(''+(i+1)+'_report').innerHTML='×';
        }
    }
    //挂钩安装
    var index1 = search_index_report('GGLJC_JD',jsonData.data.classList);
    var images = jsonData.data.classList[index1];
    if( images.GGLJC_JD.length != 0){
        for(var i = 0; i<images.GGLJC_JD.length;i++){
            var newNode = document.createElement('img');
            var type='gg';
            var url = images.GGLJC_JD[i].smallImageUrl;
            newNode.setAttribute("onclick","useHammer_report(event,"+i+",'"+type+"')");
            newNode.style = 'width: 32%;margin:margin: 1px 0 1px 1%';
            newNode.className = 'image';
            newNode.src = url;
            ggaz_report[i] = url;
            newNode.style.height = newNode.style.width;
            document.getElementById("2_1_img_report").appendChild(newNode);
        }
    }else{
        document.getElementById("2_1_img_report").style.display='none';
    }

    //防水处理
    index1 = search_index_report('FSCL_JD',jsonData.data.classList);
    images = jsonData.data.classList[index1];
    if( images.FSCL_JD.length != 0){
        for(var i = 0;i<images.FSCL_JD.length;i++){
            var newNode = document.createElement('img');
            var type = 'fs';images.FSCL_JD[i].smallImageUrl;
            newNode.setAttribute("onclick","useHammer_report(event,"+i+",'"+type+"')");
            newNode.style = 'width: 32%;margin:margin: 1px 0 1px 1%';
            newNode.className = 'image';
            newNode.src = url;
            fscl_report[i] = url;
            newNode.style.height = newNode.style.width;
            document.getElementById("2_2_img_report").appendChild(newNode);
        }
    }else{
        document.getElementById("2_2_img_report").style.display='none';
    }

    //导轨安装
    index1=search_index_report('DGAZ_JD',jsonData.data.classList);
    images = jsonData.data.classList[index1];
    if( images.DGAZ_JD.length != 0){
        for(var i = 0;i<images.DGAZ_JD.length;i++){
            var newNode = document.createElement('img');
            var type='dg';
            var url = images.DGAZ_JD[i].smallImageUrl;
            newNode.setAttribute("onclick","useHammer_report(event,"+i+",'"+type+"')");
            newNode.style = 'width: 32%;margin:margin: 1px 0 1px 1%';
            newNode.className = 'image';
            newNode.src = url;
            dgaz_report[i] = url;
            newNode.style.height=newNode.style.width;
            document.getElementById("3_img_report").appendChild(newNode);
        }
    }else{
        document.getElementById("3_img_report").style.display='none';
    }

    //组件安装
    index1=search_index_report('ZJAZ_JD',jsonData.data.classList);
    images = jsonData.data.classList[index1];
    if( images.ZJAZ_JD.length != 0){
        for(var i = 0;i<images.ZJAZ_JD.length;i++){
            var newNode = document.createElement('img');
            var type='zj';
            var url = images.ZJAZ_JD[i].smallImageUrl;
            newNode.setAttribute("onclick","useHammer_report(event,"+i+",'"+type+"')");
            newNode.style = 'width: 32%;margin:margin: 1px 0 1px 1%';
            newNode.className = 'image';
            newNode.src = url;
            zjaz_report[i] = url;
            newNode.style.height = newNode.style.width;
            document.getElementById("4_img_report").appendChild(newNode);
        }
    }else{
        document.getElementById("4_img_report").style.display='none';
    }

    //逆变器安装
    index1 = search_index_report('NBQAZ_JD',jsonData.data.classList);
    images = jsonData.data.classList[index1];
    if(images.NBQAZ_JD.length != 0){
        for(var i = 0;i<images.NBQAZ_JD.length;i++){
            var newNode = document.createElement('img');
            var type='nbq';
            var url = images.NBQAZ_JD[i].smallImageUrl;
            newNode.setAttribute("onclick","useHammer_report(event,"+i+",'"+type+"')");
            newNode.style = 'width: 32%;margin:margin: 1px 0 1px 1%';
            newNode.className = 'image';
            newNode.src = url;
            nbqaz_report[i] = url;
            newNode.style.height = newNode.style.width;
            document.getElementById("5_img_report").appendChild(newNode);
        }
    }else{
        document.getElementById("5_img_report").style.display='none';
    }

    //配电箱安装
    index1=search_index_report('PDXAZ_JD',jsonData.data.classList);
    images = jsonData.data.classList[index1];
    if( images.PDXAZ_JD.length != 0){
        for(var i = 0;i<images.PDXAZ_JD.length;i++){
            var newNode = document.createElement('img');
            var type = 'pdx';
            var url = images.PDXAZ_JD[i].smallImageUrl;
            newNode.setAttribute("onclick","useHammer_report(event,"+i+",'"+type+"')");
            newNode.style = 'width: 32%;margin:margin: 1px 0 1px 1%';
            newNode.className = 'image';
            newNode.src = url;
            pdxaz_report[i] = url;
            newNode.style.height=newNode.style.width;
            document.getElementById("6_img_report").appendChild(newNode);
        }
    }else{
        document.getElementById("6_img_report").style.display='none';
    }

    changeImage_report();
}

function search_index_report(str,data) {
    for(var i = 0;i<data.length;i++){
        for (var k in data[i]){
            if(k == str){
                return i;
            }
        }
    }
    return 0;
};//寻找对应key的序号


//----------------------调整图片-----------------------/
function changeImage_report() {
    var images = document.querySelectorAll('.image');
    if(typeof (images[0]) != 'undefined'){
        var imageWidth = images[0].offsetWidth ;
        images.forEach(function(image) {
            image.style.height = imageWidth+'px';
        });
    }
}

//------------------图片放大-----------------------------
var hammerMask_report = document.getElementById("hammer-mask_html");
var hammerBg_report = document.getElementById("hammer-bg_html");
var hammerBox_report = document.getElementById("hammer-box_html");
var hammerPage_report = document.getElementById("hammer-page_html");
var hammerImg_report = document.getElementById("image-big_html");
window.initHammer_html(hammerMask_report,hammerBg_report,hammerBox_report,hammerPage_report,hammerImg_report);

function useHammer_report(e,index,type) {
    //images: 图片url数组men
    hammerMask_report.style.top = document.body.scrollTop+"px";
    hammerBg_report.style.top = document.body.scrollTop+"px";

    switch (type){
        case "gg" : window.showHammer_html(ggaz_report,index);break;
        case "fs" : window.showHammer_html(fscl_report,index);break;
        case "zj" : window.showHammer_html(zjaz_report,index);break;
        case "dg" : window.showHammer_html(dgaz_report,index);break;
        case "nbq" : window.showHammer_html(nbqaz_report,index);break;
        case "pdx" : window.showHammer_html(pdxaz_report,index);break;
    }
}
